package com.baofu.paycore.service;

import com.baofu.paycore.common.enums.UsableFlagEnum;
import com.baofu.paycore.service.facade.model.refund.req.*;
import com.system.commons.result.PageReqDTO;
import com.system.commons.result.PageRespDTO;
import com.system.commons.result.Result;
import com.system.commons.utils.BeanCopyUtil;

import com.system.commons.utils.ExceptionUtils;
import com.system.commons.utils.PageUtil;

import com.system.commons.utils.ParamValidate;

import com.baofu.paycore.common.utils.ExceptionUtil;
import com.baofu.paycore.dal.model.RefundProductStrategyDO;
import com.baofu.paycore.dal.model.RefundStrategyDO;
import com.baofu.paycore.dal.model.RefundStrategyModeDO;
import com.baofu.paycore.dal.model.RefundStrategyPriorityDO;
import com.baofu.paycore.manager.storage.impl.RefundStrategyManager;
import com.baofu.paycore.service.facade.RefundStrategyServiceFacade;
import com.baofu.paycore.service.facade.model.refund.RefundProductStrategyResDTO;
import com.baofu.paycore.service.facade.model.refund.RefundStrategyModeResDTO;
import com.baofu.paycore.service.facade.model.refund.RefundStrategyPriorityResDTO;
import com.baofu.paycore.service.facade.model.refund.RefundStrategyResDTO;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.slf4j.helpers.SystemMarker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * description:退款配置信息操作
 *
 * <p>
 * 1.查询单条退款策略配置信息
 * 2.分页获取退款策略信息
 * 3.新增退款策略信息
 * 4.修改退款策略信息
 * 5.删除退款策略信息
 * 6.获取退款策略优先级配置信息
 * 7.分页获取退款策略优先级配置信息
 * 8.新增退款策略优先级配置信息
 * 9.修改退款策略优先级配置信息
 * 10.删除退款策略优先级配置信息
 * 11.获取退款模式配置信息
 * 12.分页获取退款模式配置信息
 * 13.新增退款模式配置信息
 * 14.修改退款模式配置信息
 * 15.删除退款模式配置信息
 * 16.获取产品退款策略关联信息
 * 17.分页获取产品退款策略关联信息
 * 18.新增产品退款策略关联表信息
 * 19.修改产品退款策略关联表信息
 * 20.删除产品退款策略关联表信息
 * </p>
 * User: liu ting  Date: 2016/4/29 ProjectName: paycore Version: 1.0
 */
@Slf4j
@Service
public class RefundStrategyService implements RefundStrategyServiceFacade {


    @Autowired
    private RefundStrategyManager refundStrategyManager;

    /**
     * 1.查询单条退款策略配置信息
     *
     * @param id 退款策略配置信息对象
     * @param traceLogId 日志ID
     * @return 返回退款策略配置信息
     */
    @Override
    public Result<RefundStrategyResDTO> selectRefundStrategy(Long id, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID, traceLogId);
        log.info("查询单条退款策略配置信息配置参数:{}" + id);
        Result<RefundStrategyResDTO> result;
        try {
            ParamValidate.validateNull(id);
            RefundStrategyDO refundStrategyDO = new RefundStrategyDO();
            refundStrategyDO.setId(id);

            List<RefundStrategyDO> listDO = refundStrategyManager.selectRefundStrategy(refundStrategyDO);
            RefundStrategyResDTO refundStrategyResDTO = BeanCopyUtil.objConvert(listDO.get(0), RefundStrategyResDTO.class);

            result = new Result<>(refundStrategyResDTO);

            return result;
        } catch (Exception e) {
            log.error("新增退款策略配置信息报错{}", e);
            result = ExceptionUtils.getResponse(e);
        }
        log.info("查询单条退款策略配置信息响应结果:{}", result);
        return result;
    }

    /**
     * 2.分页获取退款策略信息
     *
     * @param refundStrategyDTO 退款策略信息对象
     * @param pageReqDTO        分页显示参数信息
     * @param traceLogId 日志ID
     * @return list
     */
    @Override
    public Result<PageRespDTO<RefundStrategyResDTO>> selectRefundStrategyByPage(
            RefundStrategyQueryReqDTO refundStrategyDTO, PageReqDTO pageReqDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID, traceLogId);
        log.info("分页获取退款策略信息请求参数: {},{}", refundStrategyDTO, pageReqDTO);
        Result<PageRespDTO<RefundStrategyResDTO>> result;
        try {
            //校验分页参数信息是否合法
            PageUtil.checkedPageParam(pageReqDTO);

            //校验查询条件是否合法
            ParamValidate.validateParams(refundStrategyDTO);

            //对象转化
            RefundStrategyDO refundStrategyDO = BeanCopyUtil.objConvert(refundStrategyDTO, RefundStrategyDO.class);

            int count = refundStrategyManager.selectRefundStrategyOfCount(refundStrategyDO);

            List<RefundStrategyDO> listDO = refundStrategyManager.selectRefundStrategyByPage(refundStrategyDO,
                    pageReqDTO.getStartRow(), pageReqDTO.getPageCount());

            List<RefundStrategyResDTO> listDTO = BeanCopyUtil.convertList(listDO, RefundStrategyResDTO.class);

            result = new Result<>(new PageRespDTO<>(count, pageReqDTO.getPageCount(), listDTO));
        } catch (Exception e) {
            log.error("分页获取退款策略信息异常：{}", e);
            result = ExceptionUtils.getResponse(e);
        }
        log.info("分页获取退款策略信息返回信息：{}", result);
        return result;
    }

    /**
     * 3.新增退款策略信息
     *
     * @param refundStrategyDTO 退款策略信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> insertRefundStrategy(
            RefundStrategyAddReqDTO refundStrategyDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("新增退款策略信息请求参数：{}",refundStrategyDTO);
        Result<Boolean> result;
        try {
            //对象校验
            ParamValidate.validateParams(refundStrategyDTO);
            //对象转化
            RefundStrategyDO refundStrategyDO = BeanCopyUtil.objConvert(refundStrategyDTO, RefundStrategyDO.class);
            refundStrategyDO.setUsableFlag(UsableFlagEnum.USABLE.getCode());
            refundStrategyManager.insertRefundStrategy(refundStrategyDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("新增退款策略信息异常：{}", e);
            result = ExceptionUtils.getResponse(e);
        }
        log.info("新增退款策略信息请求返回结果：{}",result);
        return result;
    }

    /**
     * 4.修改退款策略信息
     *
     * @param refundStrategyDTO 退款策略信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> updateRefundStrategy(
            RefundStrategyModifyReqDTO refundStrategyDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("修改退款策略信息传入参数：{}",refundStrategyDTO);
        Result<Boolean> result;
        try {
            ParamValidate.validateParams(refundStrategyDTO);
            //对象转化
            RefundStrategyDO refundStrategyDO = BeanCopyUtil.objConvert(refundStrategyDTO, RefundStrategyDO.class);
            refundStrategyManager.updateRefundStrategy(refundStrategyDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("改退款策略信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("修改退款策略信息返回结果：{}",result);

        return result;

    }

    /**
     * 5.删除退款策略信息
     *
     * @param refundStrategyDTO 退款策略信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> deleteRefundStrategy(RefundStrategyAddReqDTO refundStrategyDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("删除退款策略信息传入参数：{}",refundStrategyDTO);
        Result<Boolean> result;
        try {
            //对象校验
            ParamValidate.validateParams(refundStrategyDTO);
            //对象转化
            RefundStrategyDO refundStrategyDO = BeanCopyUtil.objConvert(refundStrategyDTO, RefundStrategyDO.class);
            refundStrategyManager.deleteRefundStrategy(refundStrategyDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("删除退款策略信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("删除退款策略信息返回结果：{}",result);

        return result;
    }

    /**
     * 6.获取退款策略优先级配置信息
     *
     * @param id 退款策略优先级配置信息
     * @param traceLogId 日志ID
     * @return  退货规则优先级配置基本信息
     */
    @Override
    public Result<RefundStrategyPriorityResDTO> selectRefundStrategyPriority(
            Long id, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("获取退款策略优先级配置信息传入参数:{}",id);
        Result<RefundStrategyPriorityResDTO> result;
        try {
            ParamValidate.validateNull(id);
            RefundStrategyPriorityDO refundStrategyPriorityDO = new RefundStrategyPriorityDO();
            refundStrategyPriorityDO.setId(id);
            List<RefundStrategyPriorityDO> listDo = refundStrategyManager.
                    selectRefundStrategyPriority(refundStrategyPriorityDO);
            //根据id查询只能查到一条记录
            RefundStrategyPriorityDO strategyPriorityDO = listDo.get(0);
            //转换对象
            RefundStrategyPriorityResDTO refundStrategyPriorityResDTO =
                    BeanCopyUtil.objConvert(strategyPriorityDO,RefundStrategyPriorityResDTO.class);
            result = new Result<>(refundStrategyPriorityResDTO);
        } catch (Exception e) {
            log.error("获取退款策略优先级配置信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("获取退款策略优先级配置信息返回参数：{}",result);
        return result;
    }

    /**
     * 7.分页获取退款策略优先级配置信息
     *
     * @param refundStrategyPriorityDTO 策略优先级配置信息对象
     * @param pageReqDTO                 开始对象
     * @param traceLogId 日志ID
     * @return 退款策略优先级配置信息
     */
    @Override
    public Result<PageRespDTO<RefundStrategyPriorityResDTO>> selectRefundStrategyPriorityByPage(
            RefundStrategyPriorityQueryReqDTO refundStrategyPriorityDTO, PageReqDTO pageReqDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("分页获取退款策略优先级配置信息传入对象：{}",refundStrategyPriorityDTO);
        Result<PageRespDTO<RefundStrategyPriorityResDTO>> result;
        try {
            ParamValidate.validateParams(refundStrategyPriorityDTO);
            //对象转化
            RefundStrategyPriorityDO refundStrategyPriorityDO = BeanCopyUtil.objConvert(refundStrategyPriorityDTO,RefundStrategyPriorityDO.class);
            int count = refundStrategyManager.selectRefundStrategyPriorityCount(refundStrategyPriorityDO);
            List<RefundStrategyPriorityDO> listDo = refundStrategyManager.
                    selectRefundStrategyPriorityByPage(
                            refundStrategyPriorityDO, pageReqDTO.getStartRow(), pageReqDTO.getPageCount());
            List<RefundStrategyPriorityResDTO> listResDTO = BeanCopyUtil.convertList(
                    listDo, RefundStrategyPriorityResDTO.class);

            result =  new Result<>
                    (new PageRespDTO<>(count,pageReqDTO.getPageCount(),listResDTO));
        } catch (Exception e) {
            log.error("分页获取退款策略优先级配置信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("页获取退款策略优先级配置信息获取结果：{}",result);
        return result;
    }

    /**
     * 8.新增退款策略优先级配置信息
     *
     * @param refundStrategyPriorityDTO 策略优先级配置信息
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> insertRefundStrategyPriority(
            RefundStrategyPriorityAddReqDTO refundStrategyPriorityDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("新增退款策略优先级配置信息传入对象：{}",refundStrategyPriorityDTO);
        Result<Boolean> result;
        try {
            //参数校验
            ParamValidate.validateParams(refundStrategyPriorityDTO);
            //对象转化
            RefundStrategyPriorityDO refundStrategyPriorityDO = BeanCopyUtil.objConvert(
                    refundStrategyPriorityDTO, RefundStrategyPriorityDO.class);
            refundStrategyPriorityDO.setUsableFlag(UsableFlagEnum.USABLE.getCode());
            refundStrategyManager.insertRefundStrategyPriority(refundStrategyPriorityDO);
            result =  new Result<>(true);
        } catch (Exception e) {
            log.error("新增退款策略优先级配置信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("新增退款策略优先级配置信息返回结果：{}",result);
        return result;
    }

    /**
     * 9.修改退款策略优先级配置信息
     *
     * @param refundStrategyPriorityDTO 退款策略优先级配置信息对象
     * @param traceLogId 日志ID
     * @return 修改结果
     */
    @Override
    public Result<Boolean> updateRefundStrategyPriority(
            RefundStrategyPriorityModifyReqDTO refundStrategyPriorityDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("修改退款策略优先级配置信息传入对象：{}",refundStrategyPriorityDTO);
        Result<Boolean> result;
        try {
            //校验对象
            ParamValidate.validateParams(refundStrategyPriorityDTO);
            //对象转换
            RefundStrategyPriorityDO refundStrategyPriorityDO = BeanCopyUtil.objConvert(
                    refundStrategyPriorityDTO, RefundStrategyPriorityDO.class);

            refundStrategyManager.updateRefundStrategyPriority(refundStrategyPriorityDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("修改退款策略优先级配置信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("修改退款策略优先级配置信息返回结果：{}",result);
        return result;
    }

    /**
     * 10.删除退款策略优先级配置信息
     *
     * @param refundStrategyPriorityDTO 款策略优先级配置信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> deleteRefundStrategyPriority(
            RefundStrategyPriorityModifyReqDTO refundStrategyPriorityDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("删除退款策略优先级配置信息传入对象：{}",refundStrategyPriorityDTO);
        Result<Boolean> result;
        try {
            //校验对象
            ParamValidate.validateParams(refundStrategyPriorityDTO);
            //转换对象
            RefundStrategyPriorityDO refundStrategyPriorityDO = BeanCopyUtil.objConvert(
                    refundStrategyPriorityDTO, RefundStrategyPriorityDO.class);
            refundStrategyManager.deleteRefundStrategyPriority(refundStrategyPriorityDO);
            result = new Result<>(true);
        } catch (Exception e) {
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("删除退款策略优先级配置信息返回结果：{}",result);
        return result;
    }

    /**
     * 11.获取退款模式配置信息
     *
     * @param id 退款模式配置信息对象id
     * @param traceLogId 日志ID
     * @return list
     */
    @Override
    public Result<RefundStrategyModeResDTO> selectStrategyModeInfo(
            Long id, String traceLogId) {
        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("获取退款模式配置信息传入参数：{}",id);
        Result<RefundStrategyModeResDTO> result;
        try {
            //参数校验
            ParamValidate.validateNull(id);
            RefundStrategyModeDO refundStrategyModeDO = new RefundStrategyModeDO();
            refundStrategyModeDO.setId(id);
            List<RefundStrategyModeDO> listDo = refundStrategyManager.selectStrategyModeInfo(refundStrategyModeDO);
            List<RefundStrategyModeResDTO> listResDTO = BeanCopyUtil.convertList(listDo, RefundStrategyModeResDTO.class);
            //根据id查询只能返回一条信息
            RefundStrategyModeResDTO refundStrategyModeResDTO = listResDTO.get(0);
            result = new Result<>(refundStrategyModeResDTO);
        } catch (Exception e) {
            log.info("获取退款模式配置信息异常：{}",e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("获取退款模式配置信息返回结果：{}",result);
        return result;
    }

    /**
     * 12.分页获取退款模式配置信息
     *
     * @param refundStrategyModeDTO 退款模式配置信息对象
     * @param pageReqDTO 分页对象
     * @param traceLogId 日志ID
     * @return 退款模式配置信息分页对象
     */
    @Override
    public Result<PageRespDTO<RefundStrategyModeResDTO>> selectStrategyModeInfoByPage(
            RefundStrategyModeQueryReqDTO refundStrategyModeDTO, PageReqDTO pageReqDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("分页获取退款模式配置信息传入参数：{}",refundStrategyModeDTO);
        Result<PageRespDTO<RefundStrategyModeResDTO>> result;
        try {
            //校验分页信息是否合法
            PageUtil.checkedPageParam(pageReqDTO);

            //校验对象
            ParamValidate.validateParams(refundStrategyModeDTO);

            //转换对象
            RefundStrategyModeDO refundStrategyModeDO = BeanCopyUtil.objConvert(refundStrategyModeDTO, RefundStrategyModeDO.class);
            int count = refundStrategyManager.selectStrategyModeInfoCount(refundStrategyModeDO);
            List<RefundStrategyModeDO> listDO = refundStrategyManager.selectStrategyModeInfoByPage(
                    refundStrategyModeDO, pageReqDTO.getStartRow(), pageReqDTO.getPageCount());
            List<RefundStrategyModeResDTO> listResDTO = BeanCopyUtil.convertList(listDO, RefundStrategyModeResDTO.class);
            result =  new Result<>
                    (new PageRespDTO<>(count,pageReqDTO.getPageCount(),listResDTO));
        } catch (Exception e) {
            log.error("分页获取退款模式配置信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("分页获取退款模式配置信息返回结果：{}",result);
        return result;
    }

    /**
     * 13.新增退款模式配置信息
     *
     * @param refundStrategyModeDTO 退款模式配置信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> insertRefundStrategyMode(
            RefundStrategyModeAddReqDTO refundStrategyModeDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("新增退款模式配置信息传入对象:{}",refundStrategyModeDTO);
        Result<Boolean> result;
        try {
            //校验参数
            ParamValidate.validateParams(refundStrategyModeDTO);

            //对象转化
            RefundStrategyModeDO refundStrategyModeDO = BeanCopyUtil.objConvert(
                    refundStrategyModeDTO, RefundStrategyModeDO.class);
            refundStrategyModeDO.setUsableFlag(UsableFlagEnum.USABLE.getCode());
            refundStrategyManager.insertRefundStrategyMode(refundStrategyModeDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("新增退款模式配置信息异常：" + e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("新增退款模式配置信息返回结果：{}",result);
        return result;
    }

    /**
     * 14.修改退款模式配置信息
     *
     * @param refundStrategyModeDTO 退款模式配置信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> updateRefundStrategyMode(
            RefundStrategyModeModifyReqDTO refundStrategyModeDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("修改退款模式配置信息传入参数：{}",refundStrategyModeDTO);
        Result<Boolean> result;
        try {
            ParamValidate.validateParams(refundStrategyModeDTO);
            RefundStrategyModeDO refundStrategyModeDO = new RefundStrategyModeDO();
            BeanCopyUtil.copy(refundStrategyModeDTO, refundStrategyModeDO);
            refundStrategyManager.updateRefundStrategyMode(refundStrategyModeDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("修改退款模式配置信息异常：{}",e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("修改退款模式配置信息返回结果：{}",result);
        return result;
    }

    /**
     * 15.删除退款模式配置信息
     *
     * @param refundStrategyModeDTO 退款模式配置信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> deleteRefundStrategyMode(
            RefundStrategyModeModifyReqDTO refundStrategyModeDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("删除退款模式配置信息传入参数：{}",refundStrategyModeDTO);
        Result<Boolean> result;
        try {
            ParamValidate.validateParams(refundStrategyModeDTO);
            RefundStrategyModeDO refundStrategyModeDO = new RefundStrategyModeDO();
            BeanCopyUtil.copy(refundStrategyModeDTO, refundStrategyModeDO);
            refundStrategyManager.deleteRefundStrategyMode(refundStrategyModeDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("删除退款模式配置信息异常：" + e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("删除退款模式配置信息返回结果：{}",result);
        return result;
    }

    /**
     * 16.获取产品退款策略关联信息
     *
     * @param id 产品退款策略关联信息id
     * @param traceLogId 日志ID
     * @return 产品策略
     */
    @Override
    public Result<RefundProductStrategyResDTO> selectRefundProductStrategy(
            Long id, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("获取产品退款策略关联信息传入参数：{}",id);
        Result<RefundProductStrategyResDTO> result;
        try {
            //校验参数
            ParamValidate.validateNull(id);
            //转换对象
            RefundProductStrategyDO refundProductStrategyDO = new RefundProductStrategyDO();
            refundProductStrategyDO.setId(id);
            List<RefundProductStrategyDO> listDO = refundStrategyManager.selectRefundProductStrategy(
                    refundProductStrategyDO);
            List<RefundProductStrategyResDTO> listResDTO = BeanCopyUtil.convertList(
                    listDO, RefundProductStrategyResDTO.class);

            //根据id只能查询到一条记录
            RefundProductStrategyResDTO refundProductStrategyResDTO = listResDTO.get(0);

            result = new Result<>(refundProductStrategyResDTO);
        } catch (Exception e) {
            log.error("获取产品退款策略关联信息异常：" + e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("获取产品退款策略关联信息返回对象：{}",result);
        return result;
    }

    /**
     * 17.分页获取产品退款策略关联信息
     *
     * @param refundProductStrategyDTO 产品退款策略关联信息
     * @param pageReqDTO 分页对象
     * @param traceLogId 日志ID
     * @return 产品退款策略关联信息集合
     */
    @Override
    public Result<PageRespDTO<RefundProductStrategyResDTO>> selectRefundProductStrategyByPage(
            RefundProductStrategyQueryReqDTO refundProductStrategyDTO, PageReqDTO pageReqDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID,traceLogId);
        log.info("分页获取产品退款策略关联信息传入对象：{},{}"+refundProductStrategyDTO,pageReqDTO);
        Result<PageRespDTO<RefundProductStrategyResDTO>> result;
        try {

            //校验分页参数信息是否合法
            PageUtil.checkedPageParam(pageReqDTO);

            //校验参数
            ParamValidate.validateParams(refundProductStrategyDTO);
            //转化对象
            RefundProductStrategyDO refundProductStrategyDO = BeanCopyUtil.objConvert(refundProductStrategyDTO, RefundProductStrategyDO.class);

            int count = refundStrategyManager.selectRefundProductStrategyCount(refundProductStrategyDO);
            List<RefundProductStrategyDO> listDO = refundStrategyManager.
                    selectRefundProductStrategyByPage(refundProductStrategyDO, pageReqDTO.getStartRow(), pageReqDTO.getPageCount());
            //转化对象
            List<RefundProductStrategyResDTO> listResDTO = BeanCopyUtil.
                    convertList(listDO, RefundProductStrategyResDTO.class);
            result = new Result<>
                    (new PageRespDTO<>(count, pageReqDTO.getPageCount(), listResDTO));
        } catch (Exception e) {
            log.error("分页获取产品退款策略关联信息异常：" + e);
            result = ExceptionUtil.doExceptionService(e);
        }

        log.info("分页获取产品退款策略关联信息返回对象：{}",result);
        return result;

    }

    /**
     * 18.新增产品退款策略关联表信息
     *
     * @param refundProductStrategyDTO 产品退款策略关联表信息
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> insertRefundProductStrategy(
            RefundProductStrategyAddReqDTO refundProductStrategyDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID, traceLogId);
        log.info("新增产品退款策略关联表信息传入参数：{}",refundProductStrategyDTO);
        Result<Boolean> result;
        try {
            //校验传入参数
            ParamValidate.validateParams(refundProductStrategyDTO);
            //转化对象
            RefundProductStrategyDO refundProductStrategyDO =
                    BeanCopyUtil.objConvert(refundProductStrategyDTO, RefundProductStrategyDO.class);
            refundProductStrategyDO.setUsableFlag(UsableFlagEnum.USABLE.getCode());
            refundStrategyManager.insertRefundProductStrategy(refundProductStrategyDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("新增产品退款策略关联表信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("新增产品退款策略关联表信息返回对象：{}",result);
        return  result;
    }

    /**
     * 19.修改产品退款策略关联表信息
     *
     * @param refundProductStrategyDTO 产品退款策略关联表信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> updateRefundProductStrategy(
            RefundProductStrategyModifyReqDTO refundProductStrategyDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID, traceLogId);
        log.info("修改产品退款策略关联表信息传入对象：{}",refundProductStrategyDTO);
        Result<Boolean> result;
        try {
            //校验对象
            ParamValidate.validateParams(refundProductStrategyDTO);
            //转化对象
            RefundProductStrategyDO refundProductStrategyDO = BeanCopyUtil.objConvert(
                    refundProductStrategyDTO, RefundProductStrategyDO.class);
            refundStrategyManager.updateRefundProductStrategy(refundProductStrategyDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("修改产品退款策略关联表信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }

        log.info("修改产品退款策略关联表信息返回对象：{}",result);
        return result;
    }

    /**
     * 20.删除产品退款策略关联表信息
     *
     * @param refundProductStrategyDTO 产品退款策略关联表信息对象
     * @param traceLogId 日志ID
     */
    @Override
    public Result<Boolean> deleteRefundProductStrategy(
            RefundProductStrategyModifyReqDTO refundProductStrategyDTO, String traceLogId) {

        MDC.put(SystemMarker.TRACE_LOG_ID, traceLogId);
        log.info("删除产品退款策略关联表信息传入对象：{}",refundProductStrategyDTO);
        Result<Boolean> result;
        try {
            ParamValidate.validateParams(refundProductStrategyDTO);
            RefundProductStrategyDO refundProductStrategyDO = new RefundProductStrategyDO();
            BeanCopyUtil.copy(refundProductStrategyDTO, refundProductStrategyDO);
            refundStrategyManager.deleteRefundProductStrategy(refundProductStrategyDO);
            result = new Result<>(true);
        } catch (Exception e) {
            log.error("删除产品退款策略关联表信息异常：{}", e);
            result = ExceptionUtil.doExceptionService(e);
        }
        log.info("删除产品退款策略关联表信息返回对象：{}",result);
        return result;
    }
}
